package culaocham.sinhvat.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.bo.ProcessBO;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import culaocham.sinhvat.form.DangKyForm;

public class DangKyAction extends Action{
	private String hoTen;
	private String ngaySinh;
	private String tenDangNhap;
	private String matKhau;
	private String nhapLaiMatKhau;
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		DangKyForm dangKyForm = (DangKyForm) form;
		hoTen = new String(dangKyForm.getHoTenDK().getBytes("ISO8859_1"), "UTF8");
		ngaySinh = dangKyForm.getNgaySinh();
		tenDangNhap = dangKyForm.getTenDangNhap();
		matKhau = dangKyForm.getMatKhauDK();
		nhapLaiMatKhau = dangKyForm.getNhapLaiMatKhau();
		
		ProcessBO processBO = new ProcessBO();
		
		if(("".equals(hoTen)) || ("".equals(ngaySinh)) || ("".equals(tenDangNhap)) || ("".equals(matKhau))){
			request.setAttribute("empty", "empty");
			return mapping.findForward("dangKy");
		} else if(!(matKhau.equals(nhapLaiMatKhau))){
			request.setAttribute("passConfirm", "passConfirm");
			return mapping.findForward("dangKy");
		} else {
			processBO.dangKyTaiKhoan(hoTen, ngaySinh, tenDangNhap, matKhau);
			return mapping.findForward("login");
		}
	}
	
}
